package com.system.presideover.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.common.result.Result;
import com.system.presideover.entity.ContactNumber;
import com.system.presideover.entity.Emcee;
import com.system.presideover.entity.Slideshow;
import com.system.presideover.service.ContactNumberService;
import com.system.presideover.service.EmceeService;
import com.system.presideover.service.SlideshowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 司仪 前端控制器
 * </p>
 *
 * @author system
 * @since 2024-04-16
 */
@Api(tags = "司仪")
@RestController
@RequestMapping("/presideover/emcee")
public class EmceeController{

    @Autowired
    private EmceeService emceeService;

    @Autowired
    private SlideshowService slideshowService;

    @Autowired
    private ContactNumberService contactNumberService;

    @ApiOperation(value = "所有司仪")
    @GetMapping("/listEmcee")
    public Result listEmcee(){
        LambdaQueryWrapper<Emcee> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Emcee::getSort);
        List<Emcee> list = emceeService.list(wrapper);
        return Result.ok(list);
    }

    @ApiOperation(value = "查看司仪详情")
    @GetMapping("/emceelsl/{id}")
    public Result emceelsl(@PathVariable Integer id){

        List<ContactNumber> list = contactNumberService.list();
        Emcee byId = emceeService.getById(id);
        byId.setContactNumberList(list);
        return Result.ok(byId);
    }

    @ApiOperation(value = "首页展示")
    @GetMapping("/listEmceeSlideshow")
    public Result listEmceeSlideshow(){
        List lsa = new ArrayList();
        List<Slideshow> list1 = slideshowService.list();
        List<Emcee> list = emceeService.list();
        lsa.add(list1);
        lsa.add(list);
        return Result.ok(lsa);
    }



    @ApiOperation(value = "添加司仪")
    @PostMapping("/saveEmcee")
    public Result saveEmcee(@RequestBody Emcee accountNumber){
        boolean save = emceeService.save(accountNumber);

        if (save){
            return Result.ok().message("添加成功");
        }
        return Result.fail().message("添加失败");
    }


    @ApiOperation(value = "修改司仪")
    @PostMapping("/updateEmceewaha")
    public Result updateEmcee(@RequestBody Emcee accountNumber){
        boolean save = emceeService.updateById(accountNumber);

        if (save){
            return Result.ok().message("修改成功");
        }
        return Result.fail().message("修改失败");
    }

    @ApiOperation(value = "修改司仪联系投诉开启")
    @PostMapping("/updateEmceeopen")
    public Result updateEmceeByid(@RequestBody Emcee accountNumber){
        accountNumber.setStart(1);
        boolean save = emceeService.updateById(accountNumber);

        if (save){
            return Result.ok().message("修改成功");
        }
        return Result.fail().message("修改失败");
    }


    @ApiOperation(value = "修改司仪联系投诉关闭")
    @PostMapping("/updateEmceeover")
    public Result updateEmceeMiss(@RequestBody Emcee accountNumber){
        accountNumber.setStart(0);
        boolean save = emceeService.updateById(accountNumber);

        if (save){
            return Result.ok().message("修改成功");
        }
        return Result.fail().message("修改失败");
    }

    @ApiOperation(value = "删除司仪")
    @PostMapping("/delectEmcee")
    public Result delectEmcee(@RequestBody Emcee accountNumber){
        boolean save = emceeService.removeById(accountNumber.getId());

        if (save){
            return Result.ok().message("删除成功");
        }
        return Result.fail().message("删除失败");
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/{page}/{limit}")
    public Result index(@PathVariable Long page, @PathVariable Long limit, Emcee subject){

        Page<Emcee> recommendPage = new Page<>(page,limit);

        LambdaQueryWrapper<Emcee> wrapper = new LambdaQueryWrapper<>();

        Integer id = subject.getId();

        if (id!=null){
            wrapper.eq(Emcee::getId,id);
        }

        IPage<Emcee> iPage = emceeService.page(recommendPage,wrapper);

        return Result.ok(iPage);
    }

}

